package net.flintx.array;

public class FindPivotIndex {
    public int pivotIndex(int[] nums) {

        for (int i = 1; i < nums.length; i++) {
            nums[i] = nums[i - 1] + nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            int leftSum = (i == 0)? 0 : nums[i - 1];
            if (leftSum == nums[nums.length - 1] - nums[i]) {
                return i;
            }
        }
        return -1;

        // 处理下前缀和即可。注意，若 pivot index 选择为0或最末位，则其leftSum或rightSum为0
    }
}
